<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/admin/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <style>
        *{
            margin:0;
            padding:0 ;
        }
        body,html{
            width:100%;
            height:80%;
        }

        #aaa{
            margin:80px auto;
            grow:1;
            width:70%;
        }
    </style>
</head>
<body>
<div id="aaa">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" name="oldPwd" required  lay-verify="required" placeholder="请输入旧密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newPwd" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">再输一次</label>
            <div class="layui-input-block">
                <input type="password" name="newPwd1" required lay-verify="required" placeholder="请再次输入密码" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">单位</label>-->
        <!--<div class="layui-input-block">-->
        <!--<select lay-verify="required" lay-search id="danwei">-->
        <!--<option value="1">机关</option>-->
        <!--<option value="2">团体</option>-->
        <!--<option value="3">企业</option>-->
        <!--<option value="4">法人</option>-->
        <!--</select>-->
        <!--</div>-->
        <!--</div>-->

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="addWuye" lay-submit lay-filter="addWuye">提交</button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/admin/js/token.js"></script>

<script>

    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    var t = getQueryVariable("t")

    function isNull(str){
        return str == null || str == undefined || str.trim() == ""
    }

    layui.use(['form' , 'jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        //添加操作
        form.on('submit(addWuye)',function(data){
            //data.field.gongsi=$("#gongsi").find("option:selected").val();
            if(isNull(data.field.oldPwd)) {
                layer.msg("请输入旧密码")
                return false ;
            }
            if(isNull(data.field.newPwd)) {
                layer.msg("请输入新密码")
                return false ;
            }
            if(data.field.newPwd != data.field.newPwd1) {
                layer.msg("两次输入密码不一致")
                return false ;
            }
            $.ajax({
                url:t == 2 ? "/login/wy_update_password" : "/login/admin_update_password"
                ,type:"GET"
                ,contentType: 'application/json'
                ,data:data.field
                ,success:function (data) {
                    if(data.code == 200) {
                        layer.msg("修改成功")

                        setTimeout(function(){
                            if(t == 2) {
                                window.top.location = "/station.html"
                            }else if(t == 1) {
                                window.top.location = "/"
                            }
                        } , 1000)
                    }else{
                        layer.msg(data.msg)
                    }
                }
                ,error:function () {
                    console.log("ajax error");
                }
            });
            return false;
        });
    });

    var $ = layui.$;
    layui.config({
        base: '/admin/viewstyle/' //主页样式的嵌入地址
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index'], function () {

        admin = layui.admin
            , element = layui.element
            , router = layui.router();

        //解决刷新问题
        element.render();
        element.on('tab(layadmin-layout-tabs)', function (data) {
            setTimeout(function () {
                var e = document.createEvent("MouseEvents");
                e.initEvent("click", true, true);
                document.getElementById("sx").dispatchEvent(e);
            }, 20)
        });

        var active = {
            maintree1: function () {
                admin.popup({
                    title: 'yingfeituo'
                    , shade: 0
                    , anim: -1
                    , area: ['280px', '150px']
                    , id: 'layadmin-layer-skin-test'
                })
            }
            , maintree2: function () {
                top.layui.admin.popupRight({
                    id: 'LAY_adminPopupLayerTest'
                    , success: function () {
                        $('#' + this.id).html('<div class="layui-form-item">' +
                            '<div class="layui-inline ">' +
                            '<input  type="text" id="textfield" placeholder="搜索用户" class="layui-input">' +
                            '<span  id="shusearch" onclick="shusearch()" class="layui-icon layui-icon-search"></span>' +
                            '</div>' +
                            '</div><div id="maintree1" class="demo-tree demo-tree-box"></div>');
                        $("#maintree1").load("/admin/shumoxing/ztree.html");
                    }
                });
            },
        };

        $('.shuxing').on('click', function () {
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });
    });

    function goLogin(btnLogin) {
        if (btnLogin.innerHTML=='未登录')
        {
            top.location = '/index.html';
        }
    }
</script>
</body>
</html>